﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Topics.Radical.Windows.Presentation;
using Topics.Radical.Windows.Presentation.ComponentModel;

namespace SampleApp.Presentation
{
	class NotificationViewModel : AbstractViewModel, IExpectNavigatedToCallback
	{
		public NotificationViewModel()
		{
			this.Customers = new ObservableCollection<Model.Customer>();
		}

		public ObservableCollection<Model.Customer> Customers { get; private set; }

		public async void OnNavigatedTo( Topics.Radical.Windows.Presentation.ComponentModel.NavigationEventArgs e )
		{
			var client = new HttpClient();
			var customersJson = await client.GetStringAsync( "http://localhost:19324/api/customers" );

			var customers = await Newtonsoft.Json.JsonConvert.DeserializeObjectAsync<Model.Customer[]>( customersJson );

			foreach ( var customer in customers ) 
			{
				this.Customers.Add( customer );
			}
		}
	}
}
